// mapTest.go
package main

import (
	"encoding/json"
	//"net/url"
	//	"net/url"
	//	"encoding/json"
	//	"bufio"
	//	"bytes"
	//	"encoding/json"
	"errors"
	"fmt"
	"reflect"

	//	"github.com/whxmail/whx/types"
)

type strTest []string

type structTest struct {
	strTest
}

type Data map[string]interface{}

func (data Data) GetValueByKey(key string) (value reflect.Value, err error) {
	if v, ok := data[key]; ok {
		value = reflect.ValueOf(v)
	} else {
		err = errors.New("err")
	}
	return value, err
}

func pt(k chan int) {
	<-k
	fmt.Println("go running...")
}

type errchan struct {
	err chan int
}

func NewErrchan() errchan {
	c := errchan{}
	c.err = make(chan int, 1)
	return c
}

func GetInt() int {
	return 1
}

type Map0 map[string]string
type Map1 map[string]Map0

func NewMap1() map[string]map[string]string {

	m1 := make(map[string]map[string]string)
	return m1
}

func main() {
	type test struct {
		name string
	}
	test.name = "lbz"
	fmt.Println(test)
	/*
		var strArr []string
		strArr = []string{"aaa", "bbb", "ccc"}
		//fmt.Println([]byte(strArr))
		b, _ := json.Marshal(strArr)
		fmt.Println(string(b))
		/*
			ch := make(chan int)
			flag := 1
			go func() {

				for {
					<-ch
					fmt.Println("reveived")
				}
			}()
			for {
				if flag != 1 {
					ch <- 1
				}

			}
			flag = 0
			flag = 5
			/*
				err := errors.New("ERROR!")
				data := types.Data{}
				data["1"] = err.Error()
				fmt.Println(data)
				/*
					type strArr []error
					err := errors.New("hello")
					var s = strArr{err}
					b, _ := json.Marshal(s)
					fmt.Println(string(b))
					/*
						t := NewErrchan()

						t.err <- 1
						go func() {
							for {
								<-t.err
								fmt.Print("hh")
							}
						}()
						t.err <- 1
						t.err <- (err:= GetInt())
						fmt.Println("success")
						/*
							var m []string
							m = []string{"sss", "jfjsjfj"}
							m = append(m, "added")

							fmt.Println(m)
							fmt.Println(len(m))
							/*
								m := types.Error{}
								m["a"] = "1"
								fmt.Println(m)
								/*
									buf := []byte("hello world!")
									rd := bytes.NewReader(buf)
									r := bufio.NewReader(rd)
									var buff [128]byte
									n, err := r.Read(buff[:])
									fmt.Println(string(buff[:n]), err)
								{	/*
										data := types.Data{"key1": "val1", "key2": "val2"}
										src, err := json.Marshal(data)
										fmt.Println(err)
										fmt.Println(src)
										data2 := types.Data{}
										err = json.Unmarshal(src, &data2)
										fmt.Println(err)
										fmt.Println(data2)
										/*
											data := Data{"name": "liu"}
											res, _ := data.GetValueByKey("name")
											//	var t map[string]interface{}
											//	t = data
											//	rest := reflect.TypeOf(res)
											datat := reflect.TypeOf(data)
											data_name := data["name"]
											data_name_t := reflect.TypeOf(data_name)
											fmt.Println(res)
											fmt.Println(data_name_t)
											fmt.Println(datat)
											/*
												var st structTest
												str := []string{"hello", "word"}
												st.strTest = str
												fmt.Println(str)
												fmt.Println(st)
	*/
	//map test
	/*	m := make(map[string]interface{})
			m = map[string]interface{}{"liu": 123, "zhu": []interface{}{"22", "33"}}
			b, _ := json.Marshal(m)
			fmt.Println(string(b))
			parseMap(m)
		}

		func parseMap(m map[string]interface{}) {
			for k, v := range m {
				switch vv := v.(type) {
				case string:
					fmt.Println(k, vv)
				case []string:
					for k2, v2 := range vv {
						fmt.Println(k2, v2)
					}
				case int:
					fmt.Println(k, vv)
				case []int:
					for k2, v2 := range vv {
						fmt.Println(k2, v2)
					}
				case map[string]interface{}:
					fmt.Println(k)
					parseMap(vv)
				default:
					fmt.Println("None support type!")

				}
			}
	*/
}
